<?php
/**
 * Created by PhpStorm.
 * User: 64423
 * Date: 2018/10/10
 * Time: 9:49
 */

namespace app\shop\model;


use think\Model;

class GoodsCategoryModel extends Model
{
    protected $table = 'dp_goods_category';
    protected $pk = 'id';
    protected $field = true;
    protected $resultSetType = 'collection';
    public static function getList($pid=-1)
    {
        if($pid == -1){
            return self::select();
        }else{
            return self::where('pid', $pid)->select();
        }
    }


    public static function getOne($id)
    {
        return self::where('id', $id)->find();
    }

    public static function store($data, $id=0)
    {
        if($id == 0){
            // add
            return self::create($data);
        }else{
            // edit
            return self::where('id', $id)->update($data);
        }

    }

    public static function nameExist($name, $id=0)
    {
        if($id == 0){
            return self::where('name', $name)->find();
        }else{
            return self::where('name',$name)->where('id','<>',$id)->find();
        }
    }
}